Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor prices caching #3526

Merged
merged 8 commits into from
Jul 27, 2023
Merged

Refactor prices caching #3526

merged 8 commits into from
Jul 27, 2023

Conversation

hyphenized
Copy link
Contributor

@hyphenized hyphenized commented Jul 4, 2023

Relocates cached asset prices to a new redux slice. This reduces performance hits after price fetching by avoiding nested array diffs, which Immer struggles to manage. Consequently, it prevents unnecessary updates being serialized/deserialized.

To Test

This clears cached data for both account balances and assets, after switching from main to this branch:

  • Check that prices and balances are loading and displaying normally
  • Check Swaps (Quotes)
  • Check Send page (Estimates)

Latest build: extension-builds-3526 (as of Thu, 27 Jul 2023 06:33:36 GMT).

@@ -60,7 +48,6 @@ const assetsSlice = createSlice({
mappedAssets[newAsset.symbol] = [
{
...newAsset,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to spread that newAsset?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, but this has helped me spot a different bottleneck. Thanks!

Reducing the amount of updates we make to the assets slice should
improve performance and reduce blocking UI due to store updates.
The new prices slice indexes asset prices by asset ids, this way each
update is diffed and processed faster.
The now available isTrustedToken checks if assets meet these replaced
conditions, isTokenListAsset/isNetworkBaseAsset.
@hyphenized hyphenized marked this pull request as ready for review July 18, 2023 06:38
@hyphenized hyphenized mentioned this pull request Jul 18, 2023
5 tasks
Comment on lines 390 to 391
| (SmartContractFungibleAsset & { tokenLists: string[] })
| (SmartContractFungibleAsset & { verified: true }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tokenLists and verified should be at the metadata level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

This should help reduce redundancy after trust checks
Removed symbols from network base asset ids generation, added chain id
to ids for all asset types. This allows us to use these for indexing
assets across networks in e.g. redux.
Copy link
Contributor

@kkosiorowska kkosiorowska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested solutions and it seems that works well. Code looks also good, just minor comments.

background/redux-slices/earn-utils/getPoolAPR.ts Outdated Show resolved Hide resolved
background/redux-slices/earn.ts Outdated Show resolved Hide resolved
ui/hooks/nft-hooks.ts Outdated Show resolved Hide resolved
kkosiorowska
kkosiorowska previously approved these changes Jul 26, 2023
@Shadowfiend
Copy link
Contributor

@kkosiorowska looking at the outstanding comments, I'd say unless you have a clear signal that @hyphenized wants to act on any of it tomorrow morning, we land this as-is and use it to cut a small release that can go through the testing paces.

These were overlooked during the process of segregating prices from the assets slice
Copy link
Contributor

@kkosiorowska kkosiorowska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 🚀 🚀

@kkosiorowska kkosiorowska merged commit df02ccb into main Jul 27, 2023
6 checks passed
@kkosiorowska kkosiorowska deleted the priced-in branch July 27, 2023 07:08
@kkosiorowska kkosiorowska mentioned this pull request Jul 28, 2023
jagodarybacka added a commit that referenced this pull request Aug 2, 2023
## What's Changed
* v0.43.3 by @hyphenized in
#3570
* Use JSON onboarding in e2e tests of transactions by
@michalinacienciala in #3559
* Refactor prices caching by @hyphenized in
#3526
* Fix assertions made on the latest transaction by @michalinacienciala
in #3573


**Full Changelog**:
v0.43.3...v0.44.0

Latest build:
[extension-builds-3577](https://github.com/tahowallet/extension/suites/14645396551/artifacts/830824018)
(as of Fri, 28 Jul 2023 14:43:48 GMT).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants